package com.example.demo.Component;

import com.example.demo.Mapper.UserMapper;
import org.springframework.stereotype.Component;
import com.example.demo.Info.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Comparator;
import java.util.List;

@Component
public class Score {
    @Resource
    private UserMapper userMapper;
    public Object final_score(user_info userInfo,String s) {
        List<user_info> list=userMapper.all_score();
        if (s.equals("yes")){
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getUsername().equals(userInfo.getUsername())){
                    return i+1;
                }
            }
        }
        list.sort(new Comparator<user_info>() {
            @Override
            public int compare(user_info o1, user_info o2) {
                return o2.getScore()-o1.getScore();
            }
        });
        return list;
    }
}
